<?php
include "Class/EasyMySQL.php";

    $mysql = new EasyMySQL();
    if(!$mysql->Connect())  return;

    $method = $_REQUEST["Method"];
    $data = file_get_contents('php://input', 'r');
    $data = iconv("GB2312", "UTF-8//IGNORE", $data);

    if($method == "Select")
    {
        $array = $mysql->StrToArray($data);
        $provinceUID = 0;
        $cityUID = 0;
        foreach($array as $key=>$value)
        {
            if($key == "ProvinceUID")
            {
                $provinceUID = $value;
            }
            else if($key == "CityUID")
            {
                $cityUID = $value;
            }
        }

        $Names = "Office.UID AS UID,Office.Name AS Name,City.UID AS CityUID,City.Name AS CityName,Province.UID AS ProvinceUID,Province.Name AS ProvinceName";
        if($cityUID != 0)
        {
            $mysql->Select("Office",$Names)->LeftJoin("City", "Office.CityUID=City.UID")->LeftJoin("Province","City.ProvinceUID=Province.UID")->WhereSelect("Office.CityUID=".$cityUID)->QuerySelect();
        }
        else if($provinceUID != 0)
        {
            $mysql->Select("Office",$Names)->LeftJoin("City", "Office.CityUID=City.UID")->LeftJoin("Province","City.ProvinceUID=Province.UID")->WhereSelect("City.ProvinceUID=".$provinceUID)->QuerySelect();
        }
        else
        {
            $mysql->Select("Office",$Names)->LeftJoin("City", "Office.CityUID=City.UID")->LeftJoin("Province","City.ProvinceUID=Province.UID")->QuerySelect();
        }
    }
    else if($method == "Insert")
    {
        $mysql->Insert("Office")->InsertColumns("UID,Name,CityUID")->InsertValues($data, 3)->Query();
    }
    else if($method == "Update")
    {
        $array = explode("#", $data);
        $mysql->Update("Office")->UpdateSet($array[0])->WhereUpdate("UID=".$array[1])->Query();
    }
    else if($method == "Delete")
    {
        $mysql->Delete("Office")->WhereDelete("UID", $data)->Query();
    }

    $mysql->Close();
?>